class Solution 
{
public:
    int MLS(vector<int>& arr) 
    {
        int ret = 0;
        sort(arr.begin(), arr.end());
        int left = 0, n = arr.size();

        while(left < n)
        {
            int right = left+1;
            int len = 1;
            while(right < n)
            {
                if(arr[right] == arr[right-1]+1)
                {
                    len++;
                    right++;
                }
                else if(arr[right] == arr[right-1]) 
                {
                    right++;
                }
                else 
                {
                    break;
                }
            }
            ret = max(ret, len);
            left = right;
        }
        return ret;
    }
};